/* -*- c++ -*- */
/*
 * This file is part of the SD Project.
 *
 * Authors: Cleiber Marques da Silva <cleiber@lisha.ufsc.br>
 * 			Odilson Tadeu Valle <odilson@sj.ifsc.edu.br>
 * 
 * SD Project is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; version 2 of the License.
 */

#ifndef _CONFIG_H_
#define _CONFIG_H_

#include <map>
#include <string>
#include <list>

namespace sd {
	class config
	{
		private:
			// config group symbol map
			std::map<std::string, std::string> symbols;

			//config sub group map
			std::map<std::string, sd::config*> groups;
	
			// environment symbol map
			std::map<std::string, std::string> env_symbols;

			// stack of config groups for parsing
			std::list<sd::config*> group_stack;

			void split(std::string in, std::string& left, std::string& right, char c);
			void trim(std::string& s);
			void symbol_expand(std::string& s);
			void symbol_expand(std::map<std::string, std::string>& symbols, std::string& s);
			void env_symbol_expand(std::string& s);
			void add(std::string name, std::string value);

		public:
			config(){}
			config(std::string file);
			~config(){}

			// get config sub group map (e.g. for iterating over all groups)
			inline std::map<std::string, sd::config*>& get_groups() {
				return groups;
			}

			// get string config entry
			std::string type_string(std::string name);

			// get int config entry; value is parsed using atoi()
			int type_int(std::string name);
	}; 
}
#endif /* _CONFIG_H_ */
